package com.leetcode.algorithm.y22.m07;

import com.leetcode.algorithm.common.ListNode;

/**
 * 203. 移除链表元素
 * 
 * https://leetcode.cn/problems/remove-linked-list-elements/
 * 
 * @author jie.deng
 *
 */
class Question0203Solution01 {

	public ListNode removeElements(ListNode head, int val) {
		ListNode sentinel = new ListNode(-1);
		sentinel.next = head;
		ListNode prev = sentinel;
		ListNode cur = prev.next;
		while (cur != null) {
			if (cur.val == val) {
				prev.next = cur.next;
			} else {
				prev = prev.next;
			}
			cur = prev.next;
		}
		return sentinel.next;
	}

}